import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import path from 'path'

export default defineConfig(({ command }) => {
  return {
    plugins: [vue(), createSvgIconsPlugin({
      // Specify the icon folder to be cached  
      iconDirs: [path.resolve(process.cwd(), 'src/assets/svg')],
      // Specify symbolId format  
      symbolId: 'icon-[dir]-[name]',
    }),],
    base: './',
    resolve: {
      alias: {
        '@': '/src'
      },
      extensions: ['.js', '.ts', '.vue', '.json', '.css']
    },
    //需要自己新建一个存放共享的变量的文件如:src/styles/main.scss
    css: {
      preprocessorOptions: {
        scss: {
          javascriptEnabled: true,
          additionalData: '@import "./src/styles/main.scss";',
        },
      },
    },
    server: {
      port: 3000,
      open: true,
      proxy: {
        'api': {
          target: 'http://127.0.0.1:8000',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\//, '')
        }
      }
    }
  }
})